import { createRouter, createWebHistory } from 'vue-router'
//路由列表
import { appRoutes } from './modules/index'
import { RouterWhiteList } from '@/router/white-list'
import { useTitle } from '@/hooks/useTitle'

const router = createRouter({
  routes: appRoutes,
  history: createWebHistory(),
  scrollBehavior() {
    return { top: 0 }
  }
})

/**
 * 路由拦截未登录页面
 */
router.beforeEach(async (to, from, next) => {
  //在白名单内直接通过
  if (RouterWhiteList.includes(to.path)) {
    next()
    return
  }
  next()
  //设置标题
  const { setTitle } = useTitle()
  setTitle(to.meta.title + '')
})

export default router
